/**
 * 路由文件
 */

import Vue from 'vue'
import Router from 'vue-router'
import mRouter from './mRouter'
import Layout from '@/layout'
import tabbar from './tabbar'
mRouter.initRouter(Router, tabbar)
Vue.use(Router)

//静态路由列表
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [
      {
        path: '/login',
        name: 'login',
        component: () => import('@/view/login/index'),
        meta: { tabbar: false, navbar: false }
      },
      {
        path: '/test1',
        name: 'test1',
        component: () => import('@/view/test1/index'),
        meta: { text: '测试页面一' }
      },
      {
        path: '/test2',
        name: 'test2',
        component: () => import('@/view/test2/index'),
        meta: { text: '测试页面二' }
      },
      {
        path: '/test3',
        name: 'test3',
        component: () => import('@/view/test3/index'),
        meta: { text: '测试页面三', navbar: false }
      }
    ]
  },
  {
    path: '/',
    name: 'tabbar',
    component: Layout,
    children: tabbar
  },
  {
    path: '/404',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/view/404/index'),
        hidden: true
      }
    ]
  },
  {
    path: '*',
    redirect: '/404'
  }
]

//创建一个路由的工厂函数，用于创建路由和用户退出时重置路由
const createRouter = () =>
  new Router({
    mode: 'history',
    base: '/vue-vant-template',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export default router
